package login

import (
	"context"
	"github.com/zeromicro/go-zero/core/logx"
	"net/http"
	"ruoyi_zero/domain/system"
	"ruoyi_zero/internal/svc"
	"ruoyi_zero/internal/types"
	"strconv"
)

type LoginInfoLogic struct {
	logx.Logger
	ctx    context.Context
	svcCtx *svc.ServiceContext
}

func NewLoginInfoLogic(ctx context.Context, svcCtx *svc.ServiceContext) *LoginInfoLogic {
	return &LoginInfoLogic{
		Logger: logx.WithContext(ctx),
		ctx:    ctx,
		svcCtx: svcCtx,
	}
}

func (l *LoginInfoLogic) LoginInfo() (resp *types.InfoResult, err error) {
	// todo: add your logic here and delete this line

	logx.Info("LoginInfo")
	userId := l.ctx.Value("payload")

	var user = system.FindUserById(userId)
	//roles := system.SelectRolePermissionByUserId(user.UserId)
	permissions := system.GetMenuPermission(user)
	dept := system.GetDeptInfo(strconv.Itoa(user.DeptId))
	//result_map := make(map[string]interface{})
	//
	//result_map["user"] = user
	//result_map["dept"] = dept
	//result_map["userName"] = user.UserName
	//result_map["nickName"] = user.NickName
	//result_map["phonenumber"] = user.Phonenumber
	//result_map["email"] = user.Email
	//result_map["avatar"] = user.Avatar
	//result_map["avatar"] = user.Avatar
	//result_map["createTime"] = user.CreateTime

	resp = new(types.InfoResult)

	user.Dept = dept
	//user.Roles = roles
	resp.Code = http.StatusOK
	resp.Msg = "操作成功"
	resp.User = user

	//resp.Roles = roles
	//resp.Permissions = permissions

	logx.Info("---------------------")

	logx.Info("%#v", permissions)
	return
}
